package com.ruoyi.framework.config;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class SSHConnection {

    private final static int LOCAl_PORT = 33355;
    private final static int REMOTE_PORT = 3306;
    private final static int SSH_REMOTE_PORT = 22;
    private final static String SSH_USER = "root";
    private final static String SSH_PASSWORD = "1@123";
    private final static String SSH_REMOTE_SERVER = "120.24.213.11";
    private final static String MYSQL_REMOTE_SERVER = "172.17.0.3";

    private Session session; //represents each ssh session

    public void closeSSH (){
        session.disconnect();
    }

    public SSHConnection () throws Throwable{

        JSch jsch = new JSch();
        session = jsch.getSession(SSH_USER, SSH_REMOTE_SERVER,SSH_REMOTE_PORT);
        session.setPassword(SSH_PASSWORD);
        session.setConfig("StrictHostKeyChecking", "no");
        session.connect();
        session.setPortForwardingL(LOCAl_PORT, MYSQL_REMOTE_SERVER, REMOTE_PORT);

    }
}
